//
//  SY_ParentFormViewController.m
//  FaceRecognition
//
//  Created by syun on 2017/10/24.
//  Copyright © 2017年 Sylar. All rights reserved.
//

#import "SY_ParentFormViewController.h"
#import "DropTable.h"
#import "SY_StuFormCustomCell.h"
#import "SY_FormModel.h"
#import "PNChart.h"
@interface SY_ParentFormViewController ()<UITableViewDelegate,UITableViewDataSource,DropTableDelgate,UIGestureRecognizerDelegate,UIPickerViewDataSource,UIPickerViewDelegate,reloadDataDelegate>

{
  
    NSString * selStudentID;
    NSString * selScID;
    NSString * count2;
    NSString * count0;
    NSString * count1;
    NSString * count3;
    NSInteger pageNum;
    NSString *currentMonth;
    
    BOOL isOpen;
    
    NSString * thisMonth;
    NSString * thisYear;
    NSString * selectYearStr;
    NSString * lastMonth;//存储上次选择的日期
    
    EmptyStateView *noWifiView;//无网络状态
    int requestMark;//0 代表第一个接口  1第二个 2第三个

}
@property (nonatomic ,strong) UITableView * table;
@property (nonatomic ,strong) UIButton * titleView;
@property (nonatomic ,strong) UIImage * arrowImage;
@property (nonatomic ,strong) UIButton * monthButton;

@property (nonatomic ,strong) UITableView * childTable;
@property (nonatomic ,strong) UIView * backView;

@property (nonatomic, strong) NSMutableArray *studentArr;
@property (nonatomic, strong) NSMutableArray *stuNameArr;
@property (nonatomic, strong) NSMutableArray *stuIDArr;
@property (nonatomic, strong) NSMutableArray *scnameArr;
@property (nonatomic, strong) NSMutableArray *scidArr;

@property (nonatomic, strong) NSMutableArray * monthArray;
@property (nonatomic ,strong) NSMutableArray *dataArray;
@property (nonatomic ,strong) UILabel * emptyLabel;
@property (nonatomic ,strong) PNPieChart *chartView;

@property (nonatomic ,strong) MJRefreshFooter * MJ_Footer;

@property (nonatomic ,strong) UIPickerView *datePicker;
@property (nonatomic ,strong) UIControl * control;
@property (nonatomic ,strong) UIButton * sureButton;
@property (nonatomic,assign)  NSInteger indexOfMonthType;//月
@property (nonatomic,assign)  NSInteger indexOfYearType;//年
@property (nonatomic,assign)  NSString * dateString;//当前日期

@end

@implementation SY_ParentFormViewController

- (UIControl *)control
{
   if (_control == nil) {
      
      _control = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGH)];
      [_control addTarget:self action:@selector(cancelControl) forControlEvents:UIControlEventTouchUpInside];
      
      UIView * backView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGH-210, SCREENWIDTH, 210)];
      backView.backgroundColor = [UIColor whiteColor];
      [_control addSubview:backView];
      
      _sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
      _sureButton.frame = CGRectMake(SCREENWIDTH-12-40, 0, 40, 40);
      [_sureButton setTitle:@"完成" forState:UIControlStateNormal];
      [_sureButton setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
      [_sureButton addTarget:self action:@selector(chooseMonthAction:) forControlEvents:UIControlEventTouchUpInside];
      [backView addSubview:_sureButton];
      
      [_control addSubview:self.datePicker];
      
   }
   
   return _control;
}

- (UIPickerView *)datePicker {
   
   if (_datePicker == nil) {
      _datePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, SCREENHEIGH - 170, SCREENWIDTH, 170)];
      _datePicker.delegate = self;
      _datePicker.dataSource = self;
      _datePicker.showsSelectionIndicator = NO;
      _datePicker.backgroundColor=[UIColor whiteColor];
      _datePicker.userInteractionEnabled=YES;
      [_datePicker selectRow:[thisMonth integerValue]-1 inComponent:1 animated:NO];
   }
   
   return _datePicker;
}

- (NSMutableArray *)dataArray
{
   if (_dataArray == nil) {
      
      _dataArray = [NSMutableArray array];
      
   }
   return _dataArray;
}
- (UITableView *)table
{
   if (_table == nil) {
      
      _table = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, SCREENHEIGH - SafeAreaTopHeight - SafeAreaBottomHeight) style:UITableViewStylePlain];
      _table.dataSource = self;
      _table.delegate = self;
      _table.separatorStyle = UITableViewCellSeparatorStyleNone;
      _table.showsVerticalScrollIndicator = NO;
      //        _table.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
      //
      //            [self requestMoreStudentArrList];
      //
      //        }];
      //
      //        _MJ_Footer = _table.mj_footer;
      
      _emptyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 284 +(SCREENHEIGH - 348)/2, VIEW_WIDTH, 15)];
      _emptyLabel.font = [UIFont systemFontOfSize:15];
      _emptyLabel.text = @"暂无数据";
      _emptyLabel.textColor = [UIColor colorWithHexString:@"#979797"];
      _emptyLabel.textAlignment = NSTextAlignmentCenter;
      _emptyLabel.hidden = YES;
      [_table addSubview:_emptyLabel];
      
   }
   
   return _table;
}
- (UIView *)backView {
   
   if (_backView == nil) {
      _backView = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, SCREENHEIGH-SafeAreaTopHeight)];
      [_backView setBackgroundColor:[UIColor blackColor]];
      _backView.alpha = 0.5;
      _backView.hidden = YES;
      
      UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeClassTable)];
      [_backView addGestureRecognizer:tap];
   }
   return _backView;
}

- (UITableView *)childTable {
   
   if (_childTable == nil) {
      
      _childTable = [[UITableView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, 44*5) style:(UITableViewStylePlain)];
      _childTable.delegate = self;
      _childTable.dataSource = self;
      _childTable.rowHeight = 44;
      _childTable.hidden = YES;
      //        _childTable.separatorStyle = UITableViewCellSeparatorStyleNone;
   }
   return _childTable;
}

- (NSMutableArray *)monthArray
{
   if (_monthArray == nil) {
      
      _monthArray = [[NSMutableArray alloc]init];
   }
   
   return _monthArray;
   
}

- (void)cancelControl
{
   [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_down_"] forState:UIControlStateNormal];
   isOpen = NO;
   [self.control removeFromSuperview];
   
}


- (void)removeClassTable {
   _arrowImage = [UIImage imageNamed:@"record_head_classchoose_down_"];
   [_titleView setImage:_arrowImage forState:UIControlStateNormal];
   [self.childTable setHidden:YES];
   [self.backView setHidden:YES];
   
}


- (void)changeSubject:(UIButton *)sender
{
   if (self.childTable.hidden == YES) {
      [self.childTable setHidden:NO];
      [self.backView setHidden:NO];
      
      if (_stuNameArr.count > 1) {
         
         [_titleView setImage:[UIImage imageNamed:@"record_head_classchoose_up_"] forState:UIControlStateNormal];
      }else
      {
         [_titleView setImage:nil forState:UIControlStateNormal];
      }
      
      
   }else
   {
      [self.childTable setHidden:YES];
      [self.backView setHidden:YES];
      
      if (_stuNameArr.count > 1) {
         [_titleView setImage:[UIImage imageNamed:@"record_head_classchoose_down_"] forState:UIControlStateNormal];
      }else
      {
         [_titleView setImage:nil forState:UIControlStateNormal];
      }
   }
   
}

- (void)viewDidLoad {
   [super viewDidLoad];
   [self configureNav];
   
   count2 = @"0";
   count0=  @"0";
   count1=  @"0";
   count3=  @"0";
   
   currentMonth = [self getCurrentTime];
   lastMonth = currentMonth;
   [self getStudentListData];
   
   noWifiView = [[EmptyStateView alloc] initNoWifiWithFrame:CGRectMake(0, (SCREENHEIGH-SafeAreaTopHeight-175)/2, SCREENWIDTH, 175) andBackImage:@"noWifi" andBottomStr:@"网络出错啦,点击重新加载"];
   noWifiView.userInteractionEnabled= YES;
   noWifiView.delegate = self;
   [self.view addSubview:noWifiView];
   
   // Do any additional setup after loading the view.
}
- (void)reloadCurrentData
{
   self.table.hidden = NO;
   [self->noWifiView hideEmptyImage];
   if (requestMark == 0) {
      
      [self getStudentListData];
      
   }else
   {
      [self requestStudentMonthData];
      [self requestAllStudentArrList];
      
   }
   
}
-(void)configureNav{
   
   //    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
   //    self.navigationItem.leftBarButtonItem = backBtn;
   
   self.navBar.centerImg.hidden = NO;
   UIView * titleBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 120, 20)];
   _titleView = [UIButton buttonWithType:UIButtonTypeCustom];
   _titleView.frame = CGRectMake(0, 0, 120, 20);
   
   _titleView.titleLabel.font = [UIFont systemFontOfSize:17];
   [_titleView addTarget:self action:@selector(changeSubject:) forControlEvents:UIControlEventTouchUpInside];
   [_titleView setTitleColor:RGBCOLOR(59, 59, 59) forState:UIControlStateNormal];
   
   [titleBackView addSubview:_titleView];
   [self.navBar.centerImg addSubview:titleBackView];
   
   [self.view addSubview:self.table];
}

-(void)back{
   
   [self.navigationController popViewControllerAnimated:YES];
}

#pragma tableDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   if (tableView == self.table) {
      
      return 2;
   }else
   {
      return 1;
   }
   
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   if (tableView == self.table) {
      
      return 10;
   }else
   {
      return 0;
   }
   
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   
   if (tableView == self.table) {
      
      UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 10)];
      view.backgroundColor = [UIColor colorWithHexString:@"f4f5f7"];
      return view;
   }else
   {
      return nil;
      
   }
   
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
   if (tableView == self.table) {
      
      if (indexPath.section == 0) {
         
         if (indexPath.row == 0) {
            
            return 40;
         }else
         {
            return 184;
         }
      }else
      {
         if (indexPath.row == 0) {
            
            return 40;
         }else
         {
            return 39;
         }
      }
   }else
   {
      return 44;
      
   }
   
   
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   if (tableView == self.table) {
      
      if (section == 0) {
         
         return 2;
      }else
      {
         return self.dataArray.count + 1;
      }
   }else
   {
      return self.stuNameArr.count;
      
   }
   
   
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
   if (tableView == self.table) {
      
      if (indexPath.section == 0) {
         
         if (indexPath.row == 0) {
            
            UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            
            if (cell == nil) {
               
               cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
               cell.selectionStyle = UITableViewCellSelectionStyleNone;
               
               UILabel *StuLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 12, 150, 15)];
               StuLabel.font = [UIFont systemFontOfSize:16];
               StuLabel.textColor = [UIColor colorWithHexString:@"000000"];
               StuLabel.text = @"宝宝出勤";
               [cell.contentView addSubview:StuLabel];
               
               _monthButton = [UIButton buttonWithType:UIButtonTypeCustom];
               _monthButton.frame = CGRectMake(SCREENWIDTH-12-115, 0, 115, 44);
               [_monthButton setImageEdgeInsets:UIEdgeInsetsMake(0, 103, 0, 0)];
               [_monthButton setTitleColor:[UIColor colorWithHexString:@"979797"] forState:UIControlStateNormal];
               [_monthButton setTitle:currentMonth forState:UIControlStateNormal];
               if (isOpen == YES) {
                  
                  [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_up_"] forState:UIControlStateNormal];
               }else
               {
                  [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_down_"] forState:UIControlStateNormal];
               }
               
               _monthButton.titleLabel.font = [UIFont systemFontOfSize:14];
               
               [_monthButton addTarget:self action:@selector(changeMonthAction:) forControlEvents:UIControlEventTouchUpInside];
               [cell.contentView addSubview:_monthButton];
               
               UIView * line = [[UIView alloc]initWithFrame:CGRectMake(12, 39.5, SCREENWIDTH-12, 0.5)];
               line.backgroundColor = [UIColor colorWithHexString:@"dedede"];
               [cell.contentView addSubview:line];
            }
            
            return cell;
            
         }else
         {
            UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:@"cell2"];
            if (cell == nil) {
               
               cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell2"];
               
               cell.selectionStyle = UITableViewCellSelectionStyleNone;
               
            }
            
            for (UIView *view in cell.contentView.subviews) {
               
               
               [view removeFromSuperview];
               
            }
            
            NSMutableArray *arrM = [NSMutableArray array];
            
            NSArray * colorArr = @[@"e8b8f9",@"b786ca",@"ffb7cf",@"ffd6b3"];
            
            NSArray * numArr = @[count2,count0,count3,count1];
            
            NSString * txt2 = [NSString stringWithFormat:@"迟到 %@",count2];
            NSString * txt0 = [NSString stringWithFormat:@"旷课 %@",count0];
            NSString * txt3 = [NSString stringWithFormat:@"请假 %@",count3];
            NSString * txt1 = [NSString stringWithFormat:@"正常 %@",count1];
            
            NSArray * txtArr = @[txt2,txt0,txt3,txt1];
            
            NSLog(@"%@  %@  %@ ",numArr,colorArr,txtArr);
            
            for (int i = 0; i<4; i++) {
               
               NSString * colorStr = [NSString stringWithFormat:@"%@",[colorArr objectAtIndex:i]];
               
               PNPieChartDataItem *item =  [PNPieChartDataItem dataItemWithValue:[[numArr objectAtIndex:i] integerValue] color:[UIColor colorWithHexString:colorStr] description:[txtArr objectAtIndex:i]];
               
               [arrM addObject:item];
            }
            
            NSLog(@"%@",arrM);
            
            _chartView = [[PNPieChart alloc] initWithFrame:CGRectMake(30, 15, 140, 140) items:arrM];
            _chartView.descriptionTextFont  = [UIFont fontWithName:@"Avenir-Medium" size:11.0];
            _chartView.descriptionTextShadowColor = [UIColor clearColor];
            _chartView.showAbsoluteValues = NO;
            _chartView.showOnlyValues = YES;//只显示百分比
            
            [_chartView strokeChart];
            
            
            _chartView.legendStyle = PNLegendItemStyleStacked;
            _chartView.legendFont = [UIFont systemFontOfSize:15];
            
            UIView *legend = [_chartView getLegendWithMaxWidth:200];
            [legend setFrame:CGRectMake(230, 64, legend.frame.size.width, legend.frame.size.height)];
            [cell.contentView addSubview:legend];
            
            [cell.contentView addSubview:_chartView];
            
            return cell;
         }
         
      }else
      {
         
         if (indexPath.row == 0) {
            UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if (cell == nil) {
               
               cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
               
               UILabel *recodeLabel = [[UILabel alloc]initWithFrame:CGRectMake(12, 12, 150, 15)];
               recodeLabel.text = @"缺勤统计";
               recodeLabel.textColor = [UIColor colorWithHexString:@"000000"];
               recodeLabel.font = [UIFont systemFontOfSize:16];
               [cell.contentView addSubview:recodeLabel];
               
               UIView * line = [[UIView alloc]initWithFrame:CGRectMake(12, 39.5, SCREENWIDTH-12, 0.5)];
               line.backgroundColor = [UIColor colorWithHexString:@"dedede"];
               [cell.contentView addSubview:line];
            }
            
            return cell;
            
         }else
         {
            SY_FormModel * model = [self.dataArray objectAtIndex:indexPath.row - 1];
            
            SY_StuFormCustomCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SY_StuFormCustomCell"];
            if (cell == nil) {
               
               cell = [[SY_StuFormCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SY_StuFormCustomCell"];
            }
            
            cell.timeLabel.text = model.date;
            
            if ([model.arrival intValue] == 2) {
               
               cell.numAndState.text = @"迟到";
               
            }else if ([model.arrival intValue] == 0)
            {
               cell.numAndState.text = @"旷课";
            }else if ([model.arrival intValue] == 3)
            {
               cell.numAndState.text = @"请假";
            }else if ([model.arrival intValue] == 1)
            {
               cell.numAndState.text = @"正常到校";
               
            }else if ([model.arrival intValue] == 4)
            {
               cell.numAndState.text = @"休息";
            }
            
            return cell;
         }
      }
   }else
   {
      UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
      if (cell == nil) {
         
         cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
      }
      cell.textLabel.text =[NSString stringWithFormat:@"%@ %@",[_scnameArr objectAtIndex:indexPath.row],[_stuNameArr objectAtIndex:indexPath.row]];
      
      return cell;
   }
   
}

- (void)changeMonthAction:(UIButton *)sender
{
   NSLog(@"button.f = %f,%f,%f,%f",sender.frame.origin.x,sender.frame.origin.y,sender.frame.size.width,sender.frame.size.height);
   isOpen = !isOpen;
   if (isOpen == YES) {
      
      [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_up_"] forState:UIControlStateNormal];
   }else
   {
      [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_down_"] forState:UIControlStateNormal];
   }
   
   UIWindow *window = KeyWindow;
   [window addSubview:self.control];
}
- (void)chooseMonthAction:(UIButton *)sender
{
   
   if ((_indexOfMonthType + 1) < 10) {
      
      currentMonth = [NSString stringWithFormat:@"%ld-0%ld",    [thisYear integerValue]-_indexOfYearType,_indexOfMonthType+1];
   }else
   {
      currentMonth = [NSString stringWithFormat:@"%ld-%ld",    [thisYear integerValue]-_indexOfYearType,_indexOfMonthType+1];
   }
   
   if (![lastMonth isEqualToString:currentMonth]) {
      
      [_monthButton setTitle:currentMonth forState:(UIControlStateNormal)];
      
      [self requestStudentMonthData];
      [self requestAllStudentArrList];
      
      lastMonth = currentMonth;
   }
   
   [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_down_"] forState:UIControlStateNormal];
   isOpen = NO;
   [self.control removeFromSuperview];
}

#pragma mark -DropTableDelegate
//切换月份
- (void)tableViewCellSelected:(NSInteger)index{
   
   currentMonth = [self.monthArray objectAtIndex:index];
   [_monthButton setTitle:currentMonth forState:UIControlStateNormal];
   [_monthButton setImage:[UIImage imageNamed:@"record_head_classchoose_down_"] forState:UIControlStateNormal];
   [self requestStudentMonthData];
   [self requestAllStudentArrList];
}
#pragma mark - Request

//获取学生列表
- (void)getStudentListData {
   
   NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
   [dict setObject:USERID forKey:@"parentid"];
   
   [Utils Java_get:@"api/getChildClass" parameters:dict success:^(NSInteger recode, id jsonObject) {
      
      NSDictionary * dict = (NSDictionary *)jsonObject;
      if ([[dict objectForKey:@"re_code"] integerValue]==0) {
         if ([[dict objectForKey:@"re_data"] count]>0) {
            
            NSLog(@"dict = %@",dict);
            
            self.studentArr = [dict objectForKey:@"re_data"];
            
            self.stuNameArr = [[NSMutableArray alloc]init];
            
            self.stuIDArr = [[NSMutableArray alloc]init];
            
            self.scnameArr = [[NSMutableArray alloc]init];
            
            self.scidArr = [[NSMutableArray alloc]init];
            
            for (NSDictionary *dic in self.studentArr) {
               
               [self.stuNameArr addObject:[dic valueForKey:@"studentname"]];
               [self.stuIDArr addObject:[dic valueForKey:@"studentid"]];
               [self.scnameArr addObject:[dic valueForKey:@"scname"]];
               [self.scidArr addObject:[dic valueForKey:@"scid"]];
            }
            
            NSString *titleStr = [self.stuNameArr objectAtIndex:0];
            selStudentID = [self.stuIDArr objectAtIndex:0];
            selScID = [self.scidArr objectAtIndex:0];
            
            [self requestStudentMonthData];
            [self requestAllStudentArrList];
            
            [self.titleView setTitle:titleStr forState:UIControlStateNormal];
            
            CGSize size = [self getButtonStringWidth:titleStr];
            
            if (self.studentArr.count > 1) {
               
               [_titleView setEnabled:YES];
               _arrowImage = [UIImage imageNamed:@"record_head_classchoose_down_"];
               [self getButton:_titleView LeftStringSize:size AndRightImage:_arrowImage];
               
               [self.view addSubview:self.backView];
               [self.view addSubview:self.childTable];
               
               if (44*self.stuNameArr.count > SCREENHEIGH - 64 - 44) {
                  self.childTable.scrollEnabled = YES;
                  [self.childTable setHeight:SCREENHEIGH - 64 - 44];
               }else {
                  
                  [self.childTable setHeight:44 * self.stuNameArr.count];
                  self.childTable.scrollEnabled = NO;
               }
               
            }else
            {
               [_titleView setImage:nil forState:UIControlStateNormal];
               [_titleView setEnabled:NO];
            }
            
         }
         
      }
      
   } failure:^(NSInteger recode, NSError *error) {
      
      if (error.code == -1009) {
         self.table.hidden = YES;
         [self->noWifiView showEmptyImage];
         requestMark = 0;
      }
      
   }];
   
}

-(void)downMonth
{
   RequestParam *param = [[RequestParam alloc] init];
   param.method = @"sy_rollcall_getmonth";
   
   [Utils get:nil parameters:param.mj_keyValues success:^(NSInteger recode, id jsonObject) {
      
      NSDictionary *dict = (NSDictionary *)jsonObject;
      NSArray * array = [dict objectForKey:@"re_data"];
      if (array.count > 0) {
         
         for (int i = 0 ; i< array.count; i++) {
            
            [self.monthArray addObject:[[array objectAtIndex:i] objectForKey:@"month"]];
            
         }
         
      }
      NSLog(@"%@",dict);
   } failure:^(NSInteger recode, NSError *error) {
      
      [self showHint:error.localizedDescription];
   }];
   
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (tableView == self.childTable) {
      
      NSString * stuStr = [_stuNameArr objectAtIndex:indexPath.row];
      selStudentID = [_stuIDArr objectAtIndex:indexPath.row];
      selScID =  [_scidArr objectAtIndex:indexPath.row];
      [self requestStudentMonthData];
      [self requestAllStudentArrList];
      
      CGSize size = [self getButtonStringWidth:stuStr];
      
      [_titleView setTitle:stuStr forState:UIControlStateNormal];
      _arrowImage = [UIImage imageNamed:@"record_head_classchoose_down_"];
      [self getButton:_titleView LeftStringSize:size AndRightImage:_arrowImage];
      
      [_backView setHidden:YES];
      [_childTable setHidden:YES];
   }
}
#pragma mark - PickerDelegate & PickerDataSource

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
   
   return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
   
   
   if (component == 0) {
      return 100;
   }else
   {
      return 12;
   }
   
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
   
   
   if (component==0) {
      
      return [NSString stringWithFormat:@"%ld年",[thisYear intValue]-row];
   }else {
      return [NSString stringWithFormat:@"%ld月",row+1];
      
   }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
   
   if (component == 0) {
      
      self.indexOfYearType = row;
      
   }else {
      
      self.indexOfMonthType = row;
   }
}

-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
   
   return 200;
}

- (NSString *)getCurrentTime {
   NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
   [formatter setDateFormat:@"yyyy-MM"];
   NSString *dateTime = [formatter stringFromDate:[NSDate date]];
   thisYear = [dateTime componentsSeparatedByString:@"-"][0];
   
   thisMonth = [dateTime componentsSeparatedByString:@"-"][1];
   
   _indexOfMonthType = [thisMonth integerValue] - 1;
   
   if ([thisMonth integerValue] < 10) {
      
      dateTime = [NSString stringWithFormat:@"%ld-0%ld",    [thisYear integerValue],[thisMonth integerValue]];
   }
   
   return dateTime;
}

- (void)requestStudentMonthData
{
   NSMutableDictionary *requestDic = [NSMutableDictionary dictionary];
   
   [requestDic setObject:selScID forKey:@"scid"];
   [requestDic setObject:[NSString stringWithFormat:@"%@-01",currentMonth] forKey:@"date"];
   [requestDic setObject:selStudentID forKey:@"userid"];
   [Utils Java_get:@"api/getStudentMonthTotle" parameters:requestDic success:^(NSInteger recode, id jsonObject) {
      
      
      NSArray *arr = [jsonObject objectForKey:@"re_data"];
      NSLog(@"arr = %@",arr);
      
      if (arr.count > 3) {
         
         count2 = [[arr objectAtIndex:2]objectForKey:@"count"];
         count0=  [[arr objectAtIndex:0]objectForKey:@"count"];
         count1=  [[arr objectAtIndex:1]objectForKey:@"count"];
         count3=  [[arr objectAtIndex:3]objectForKey:@"count"];
      }else
      {
         count2 = @"0";
         count0=  @"0";
         count1=  @"0";
         count3=  @"0";
      }
      
      [self.table reloadData];
      
   }failure:^(NSInteger recode, NSError *error) {
      
      if (error.code == -1009) {
         self.table.hidden = YES;
         [self->noWifiView showEmptyImage];
         requestMark = 1;
      }
   }];
}

- (void)requestAllStudentArrList
{
   //    pageNum = 1;
   //    if (_table.mj_footer == nil) {
   //
   //        _table.mj_footer = _MJ_Footer;
   //    }
   NSMutableDictionary *requestDic = [NSMutableDictionary dictionary];
   
   [requestDic setObject:selScID forKey:@"scid"];
   [requestDic setObject:selStudentID forKey:@"userid"];
   [requestDic setObject:[NSString stringWithFormat:@"%@-01",currentMonth] forKey:@"date"];
   [Utils Java_get:@"api/getStudentArrList" parameters:requestDic success:^(NSInteger recode, id jsonObject) {
      
      
      [self.dataArray removeAllObjects];
      
      NSArray *arr = [jsonObject objectForKey:@"re_data"];
      NSLog(@"arr = %@",arr);
      if (arr.count == 0) {
         
         [_emptyLabel setHidden:NO];
         [self.table reloadData];
         return;
      }else
      {
         [_emptyLabel setHidden:YES];
         
         //            if (arr.count == 10) {
         //
         //                for ( NSDictionary * dic in arr) {
         //
         //                    SY_FormModel * model = [SY_FormModel mj_objectWithKeyValues:dic];
         //                    [self.dataArray addObject:model];
         //                }
         //                pageNum =2;
         //                [self.table.mj_footer endRefreshing];
         
         //            }else
         //            {
         for ( NSDictionary * dic in arr) {
            
            SY_FormModel * model = [SY_FormModel mj_objectWithKeyValues:dic];
            [self.dataArray addObject:model];
         }
         //                [self.table.mj_footer endRefreshingWithNoMoreData];
         //            }
         
         
      }
      
      [self.table reloadData];
      
   }failure:^(NSInteger recode, NSError *error) {
      
      if (error.code == -1009) {
         self.table.hidden = YES;
         [self->noWifiView showEmptyImage];
         requestMark = 2;
      }
   }];
}

//- (void)requestMoreStudentArrList
//{
//    NSMutableDictionary *requestDic = [NSMutableDictionary dictionary];
//
//    NSString * scid = [SYAccountTool ShareAccount].account.scid;
//    [requestDic setObject:scid forKey:@"scid"];
//    [requestDic setObject:selStudentID forKey:@"userid"];
//    [requestDic setObject:[NSString stringWithFormat:@"%ld",(long)pageNum] forKey:@"pageno"];
//    [requestDic setObject:@"10" forKey:@"pagesize"];
//    [Utils Java_get:@"api/getStudentArrList" parameters:requestDic success:^(NSInteger recode, id jsonObject) {
//
//    NSArray *arr = [jsonObject objectForKey:@"re_data"];
//
//      if (arr.count == 10){
//
//            for ( NSDictionary * dic in arr) {
//
//                SY_FormModel * model = [SY_FormModel mj_objectWithKeyValues:dic];
//                [self.dataArray addObject:model];
//            }
//
//          pageNum ++;
//
//          [self.table.mj_footer endRefreshing];
//
//        }else
//        {
//            for ( NSDictionary * dic in arr) {
//
//                SY_FormModel * model = [SY_FormModel mj_objectWithKeyValues:dic];
//                [self.dataArray addObject:model];
//            }
//            [self.table.mj_footer endRefreshingWithNoMoreData];
//        }
//
//        [self.table reloadData];
//
//    }failure:^(NSInteger recode, NSError *error) {
//
//        [self showHint:@"网络异常，请稍后重试！"];
//
//        [self.table.mj_footer endRefreshingWithNoMoreData];
//    }];
//}
//获取字符串的宽度并

- (CGSize)getButtonStringWidth:(NSString *)string
{
   CGSize oriSize = CGSizeMake(10000, 20);
   
   CGSize size = [string boundingRectWithSize:oriSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size;
   return size;
}
//设置UIbutton左文字右图片
- (void)getButton:(UIButton *)button  LeftStringSize:(CGSize)size AndRightImage:(UIImage *)image
{
   [button setImage:image forState:UIControlStateNormal];
   [button setTitleEdgeInsets:UIEdgeInsetsMake(0, -image.size.width, 0, image.size.width)];
   [button setImageEdgeInsets:UIEdgeInsetsMake(0,size.width+3, 0,- (size.width+3))];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
